<?php
/**
 * This class is represents an user.
 * @author Pouja Nikray
 */
class User{
    private $userName;
    private $genres;
    private $favorites;
    private $playlists;
    private $email;
    private $id;
    /**
     * Constructor
     */
    public function User(){
        $this->genres=array();
        $this->favorites=array();
        $this->playlists=array();
    }
    /**
     * Returns the id of this user
     * @return int The id of this user
     */
    public function id(){
        return $this->id;
    }
    /**
     * Sets the id of the user
     * @param int $id The id that has to be set
     */
    public function setID($id){
        if((int)is_int($id)){
            $this->id=$id;
        }
    }
    /**
     * Returns the user name
     * @return String the user name
     */
    public function userName(){
        return $this->userName;
    }
    /**
     * Sets the user name
     * @param String $userName The user name has to be set
     */
    public function setUserName($userName){
        $this->userName=$userName;
    }
    /**
     * Returns the email adres of this user
     * @return String The email adres
     */
    public function email(){
        return $this->email;
    }
    /**
     * Sets the email adres of this user
     * @param String $email The email adres that has to be set
     */
    public function setEmail($email){
        $this->email=$email;
    }
    /**
     * Returns the index of the given genre
     * @param String $genre The genre
     * @return int index
     */
    private function keyGenre($genre){
        for($i=0;$i<count($this->genres);$i++){
            if(strcmp($genre, $this->genres[$i][0])==0){
                return $key;
            }
        }
        return -1;
    }
    /**
     * Adds the genre to the list
     * @param String $genre The genre to be added
     */
    public function addGenre($genre){
        if($this->keyGenre($genre)==-1){
            array_push($this->genres, $genre);
        }
    }

    /**
     * If genre is null, it returns the all the genres where the user has listened to
     * @param object $genre Either null or a string
     */
    public function getGenre($genre){
        if($genre==null){
            return $this->genres;
        }
        $key=$this->keyGenre($genre);
        if($key!=-1){
            return $this->genres[$key];
        }
        return null;
    }
    
    /*
     * DEPRECATED
     * The function below were used in previously design of the software
     *  
    private function keyFavorite($favorite){
        for($i=0;$i<count($this->favorites);$i++){
            if($favorite->equals($this->favorites[$i])){
                return $key;
            }
        }
        return -1;
    }
    public function addFavorite($album){
        if($this->keyFavorite($album)==-1){
            array_push($this->favorites, $album);
        }
    }
    public function getFavorite($favorite){
        if($favorite==null){
            return $this->favorites;
        }
        $key=$this->keyFavorite($album);
        if($key!=-1){
            return $this->favorites[$key];
        }
        return null;
    }
    
    
    private function keyPlaylist($playlist){
        for($i=0;$i<count($this->genres);$i++){
            if($playlist->equals($this->playlist[$i])){
                return $key;
            }
        }
        return -1;
    }
    public function addPlaylist($playlist){
        if($this->keyPlaylist($playlist)==-1){
            array_push($this->playlists, $playlist);
        }
    }
    public function getPlaylist($playlist){
        if($playlist==null){
            return $this->playlists;
        }
        $key=$this->keyPlaylist($playlist);
        if($key!=-1){
            return $this->playlists[key];
        }
        return null;
    }
     * 
     */
}
?>
